#include "NotesManager.h"

NotesManager::NotesManager(
	int frame_size_x, int frame_size_y,
	double frame_rate,
	std::vector<NoteStream>& streams,
	std::map<std::string, Color>& colors,
	Byte alpha,
	double play_speed,
	int record_radius,
	double border_brightness,
	double center_brightness,
	double border_radius,
	double middle_color_loc
) :MLObj(frame_size_x, frame_size_y, frame_rate) {
	std::cout << (char*)u8"正在初始化音符轨道……" << std::endl;
	size_t tracks_num = streams.size();
	GLuint glsl = Utils::activateShader("./GLSL/DoubleSectorVertex.glsl", "./GLSL/DoubleSectorFragment.glsl");
	_mix_glsl = Utils::activateShader("./GLSL/MixVertex.glsl", "./GLSL/MixFragment.glsl");
	for (size_t i = 0; i < tracks_num; i++) {
		NotesTrack track(
			streams[i],
			frame_size_x, frame_size_y,
			frame_rate,
			tracks_num,
			i,
			colors[streams[i].name],
			alpha,
			play_speed,
			glsl,
			_mix_glsl,
			record_radius,
			border_brightness,
			center_brightness,
			border_radius,
			middle_color_loc
		);
		_tracks.push_back(track);
	}
}

NotesManager::~NotesManager() {
	_tracks.clear();
}


void NotesManager::clear() {
	for (size_t i = 0; i < _tracks.size(); i++) {
		_tracks[i].clear();
	}
	_tracks.clear();
}

void NotesManager::get_frame(size_t frame_index, MLFrame& frame) {
	for (size_t i = 0; i < _tracks.size(); i++) {
		_tracks[i].get_frame(frame_index, frame);
	}
}
